package com.wowudi.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wowudi.domain.Drug;
import com.wowudi.service.DrugService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("main")
@RestController
@CrossOrigin
public class DrugController {

    @Autowired
    DrugService DrugService;

    @RequestMapping("findAll")
    public Page findAll(Integer size,Integer current,String name){
        Page Page= DrugService.findAllBySearch(size,current,name);
        return Page;
    }

    @RequestMapping("updateStatusById")
    public String updateStatusById(int id,String status){
        System.out.println(id+status);
        DrugService.updateStatusById(status,id);
        return  "main/findAll";
    }


    @RequestMapping("addDrug")
    public String addDrug(Drug Drug){
        System.out.println(Drug);
        boolean b = DrugService.addDrug(Drug);
        if(b){
            return "添加成功";
        }else{
            return "添加失败";
        }
    }

    @RequestMapping("updateDrug")
    public String updateDrug(Drug Drug){
        System.out.println(Drug);
        boolean b= DrugService.updateById(Drug);
        if(b){
            return "修改成功";
        }else{
            return "修改失败";
        }
    }
}
